<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\BaseController;
use App\Http\Controllers\Controller;
use App\Http\Controllers\utils\Common;
use App\Models\Api\Source;
use Illuminate\Support\Facades\Validator;
use Illuminate\Http\Request;

class SourceController extends BaseController
{
    function __construct()
    {
        $this->common = new Common();
    }
    /**
     * Display a listing of the resource.
     */
    public function index(Request $request)
    {
        //
        // $data =  Source::get();
        $params = $request->all();
        $limit = isset($params['limit']) ? $params['limit'] : 10;
        $data = Source::simplePaginate($limit);
        return $this->responseData($data, '获取成功', 200);
    }

    /**
     * Store a newly created resource in storage.
     */
    public function store(Request $request)
    {
        $validateList = [
            'source' => 'required',
        ];
        $params = $request->all();
        $params['createtime'] = now();
        $params['status'] = 1;
        return $this->common->apiAdd(Source::class, $request, $validateList, $params);
    }

    /**
     * Display the specified resource.
     */
    public function show(string $id)
    {

        return $this->responseData([], '获取成功,但不提供数据', 204);
    }

    /**
     * Update the specified resource in storage.
     */
    public function update(Request $request, string $id)
    {
        return $this->common->apiEdit(Source::class, $request, $id);
    }

    /**
     * Remove the specified resource from storage.
     */
    public function destroy(Request $request, string $id)
    {
        return $this->common->apiDelete(Source::class, $request, $id);
    }
}
